package com.thtf.openguess.service.impl;

import com.thtf.openguess.aop.annotation.Time;
import com.thtf.openguess.openguess.*;
import com.thtf.openguess.service.*;
import com.thtf.openguess.util.Util;
import org.springframework.stereotype.Service;
import uk.co.jemos.podam.api.DataProviderStrategy;
import uk.co.jemos.podam.api.PodamFactory;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;

@Service
public class TestAllServiceImpl implements TestAllService {

//    public String[] year = {"2000","2001","2002","2003","2004","2005","2006","2007","2008","2009","2010",
//            "2011","2012","2013","2014","2015","2016","2017","2018","2019","2020","2021","2022"};
    public String[] year = {"2022"};
    public String[] month = {"01","02","03","04","05","06","07","08","09","10","11","12"};

    @Resource
    private PodamFactory podamFactory;
    @Resource
    private GyMlFz0002Service gyMlFz0002Service;
    @Resource
    private GyMlFz0004Service gyMlFz0004Service;
    @Resource
    private GyMlFz0040Service gyMlFz0040Service;
    @Resource
    private GyMlFz0043Service gyMlFz0043Service;
    @Resource
    private GyMlFz0087Service gyMlFz0087Service;
    @Resource
    private GyMlMl0045Service gyMlMl0045Service;
    @Resource
    private C2016000000B20411Service c2016000000B20411Service;
    @Resource
    private C2016000000B204121bService c2016000000B204121bService;
    @Resource
    private C2016000000B204122bService c2016000000B204122bService;
    @Resource
    private C2016000000B204123bService c2016000000B204123bService;
    @Resource
    private C201600000020111Service c201600000020111Service;
    @Resource
    private AsyncService asyncService;

    @Override
    public String insertCatalogue(Integer sqlNum) {
        List<GyMlFz0002> gyMlFz0002s= new ArrayList<>();
        List<GyMlFz0004> gyMlFz0004s= new ArrayList<>();
        List<GyMlFz0040> gyMlFz0040s= new ArrayList<>();
        List<GyMlFz0043> gyMlFz0043s= new ArrayList<>();
        List<GyMlFz0087> gyMlFz0087s= new ArrayList<>();
        List<GyMlMl0045> gyMlMl0045s= new ArrayList<>();
        for (int i =0 ; i< sqlNum ;i++){
            gyMlFz0002s.add(Util.forEachSetValue(new GyMlFz0002()).setFz0002dm(String.valueOf(i)).setBb("201111010").setFz0002mc(String.valueOf(i)).setCjdm(String.valueOf(i)));
            gyMlFz0004s.add(Util.forEachSetValue(new GyMlFz0004()).setFz0004dm(String.valueOf(i)).setBb("201111010").setFz0004mc(String.valueOf(i)).setCjdm(String.valueOf(i)));
            gyMlFz0040s.add(Util.forEachSetValue(new GyMlFz0040()).setFz0040dm(String.valueOf(i)).setBb("201111010").setFz0040mc(String.valueOf(i)).setCjdm(String.valueOf(i)));
            gyMlFz0043s.add(Util.forEachSetValue(new GyMlFz0043()).setFz0043dm(String.valueOf(i)).setBb("201111010").setFz0043mc(String.valueOf(i)).setCjdm(String.valueOf(i)));
            gyMlFz0087s.add(Util.forEachSetValue(new GyMlFz0087()).setFz0087dm(String.valueOf(i)).setBb("201111010").setFz0087mc(String.valueOf(i)).setCjdm(String.valueOf(i)));
            gyMlMl0045s.add(Util.forEachSetValue(new GyMlMl0045()).setMl0045dm(String.valueOf(i)).setBb("201111010").setMl0045mc(String.valueOf(i)).setCjdm(String.valueOf(i)));
        }
        gyMlFz0002Service.saveBatch(gyMlFz0002s);
        gyMlFz0004Service.saveBatch(gyMlFz0004s);
        gyMlFz0040Service.saveBatch(gyMlFz0040s);
        gyMlFz0043Service.saveBatch(gyMlFz0043s);
        gyMlFz0087Service.saveBatch(gyMlFz0087s);
        gyMlMl0045Service.saveBatch(gyMlMl0045s);
        return null;
    }

    @Override
    @Time
    public String insertBaseData(Integer sqlNum,Integer boundNum,Integer threadNum) throws InterruptedException {
        //需要新增5张表的data，两张主表的3个字段相同，子表的根据主表分别加5张
        CountDownLatch countDownLatch = new CountDownLatch(threadNum);
        for (int n = 1; n <= threadNum; n++) {
            asyncService.dealAdd(boundNum, countDownLatch, sqlNum,podamFactory,c2016000000B20411Service,c2016000000B204121bService,c2016000000B204122bService,c2016000000B204123bService,c201600000020111Service);
        }
        countDownLatch.await();
        return null;
    }

}
